package com.yimu.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yimu.common.annotation.Log;
import com.yimu.common.enums.BusinessType;
import com.yimu.system.domain.Monitor;
import com.yimu.system.service.IMonitorService;
import com.yimu.common.core.controller.BaseController;
import com.yimu.common.core.domain.AjaxResult;
import com.yimu.common.utils.poi.ExcelUtil;
import com.yimu.common.core.page.TableDataInfo;

/**
 * 监听管理Controller
 * 
 * @author Christine
 * @date 2020-08-26
 */
@Controller
@RequestMapping("/system/monitor")
public class MonitorController extends BaseController
{
    private String prefix = "system/monitor";

    @Autowired
    private IMonitorService monitorService;

    @RequiresPermissions("system:monitor:view")
    @GetMapping()
    public String monitor()
    {
        return prefix + "/monitor";
    }

    /**
     * 查询监听管理列表
     */
    @RequiresPermissions("system:monitor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Monitor monitor)
    {
        startPage();
        List<Monitor> list = monitorService.selectMonitorList(monitor);
        return getDataTable(list);
    }

    /**
     * 导出监听管理列表
     */
    @RequiresPermissions("system:monitor:export")
    @Log(title = "监听管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Monitor monitor)
    {
        List<Monitor> list = monitorService.selectMonitorList(monitor);
        ExcelUtil<Monitor> util = new ExcelUtil<Monitor>(Monitor.class);
        return util.exportExcel(list, "monitor");
    }

    /**
     * 新增监听管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存监听管理
     */
    @RequiresPermissions("system:monitor:add")
    @Log(title = "监听管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Monitor monitor)
    {
        return toAjax(monitorService.insertMonitor(monitor));
    }

    /**
     * 修改监听管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Monitor monitor = monitorService.selectMonitorById(id);
        mmap.put("monitor", monitor);
        return prefix + "/edit";
    }

    /**
     * 修改保存监听管理
     */
    @RequiresPermissions("system:monitor:edit")
    @Log(title = "监听管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Monitor monitor)
    {
        return toAjax(monitorService.updateMonitor(monitor));
    }

    /**
     * 删除监听管理
     */
    @RequiresPermissions("system:monitor:remove")
    @Log(title = "监听管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(monitorService.deleteMonitorByIds(ids));
    }
}
